<script src="__PUBLIC__/js/artDialog/jquery.artDialog.js?skin=default"></script>
<script src="__PUBLIC__/js/artDialog/plugins/iframeTools.js"></script>
<script src="__PUBLIC__/js/date/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/datepicker.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/WdatePicker.css">
<style type="text/css">
a.a_upload,a.a_choose{
	border:1px solid #3d810c;
	box-shadow:0 1px #cccccc;
	-moz-box-shadow:0 1px #cccccc;
	-webkit-box-shadow:0 1px #cccccc;
	cursor:pointer; 
	display: inline-block;
	text-align: center;
	vertical-align:bottom;
	overflow:visible;
	border-radius:3px;
	-moz-border-radius:3px;
	-webkit-border-radius:3px;
	vertical-align:middle;
	background-color: #f1f1f1;
	background-image: -webkit-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	background-image: -moz-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	background-image: -ms-linear-gradient(bottom, #ccc 0%, #e5e5e5 3%, #fff 97%, #fff 100%);
	color: #000;
	border:1px solid #aaa;
	padding:2px 8px 2px 8px;
	text-shadow: 0 1px #ffffff;
	font-size: 14px;
	line-height: 1.5;
}
</style>
<div class="pd-20">
    <form action="" method="post" class="form form-horizontal" action="{:U("Admin/Order/addPeriod", array('periodid' => '1'))}" onsubmit="return checkForm()">
    	<input type="hidden" name="periodid" value="{$period['periodid']}">
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>期数</label>
            <div class="col-6">
	            <input type="text" class="input-text" value="{$period['pname']}" placeholder="" id="pname" name="pname" datatype="*2-16" nullmsg="" <if condition="$period['periodid'] neq null">disabled="disabled"</if>>
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>期数名称</label>
            <div class="col-6">
	            <input type="text" class="input-text" value="{$period['ppname']}" placeholder="*月第*期" id="ppname" name="ppname" datatype="*2-16" nullmsg="" <if condition="$period['periodid'] neq null">disabled="disabled"</if>>
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>开始时间</label>
            <div class="col-6">
	            <input type="input" class="px" id="fromtime" name="fromtime" value="{$period.fromtime}"  placeholder="2016-01-01 01:02:03" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})">
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
        	<label class="form-label col-3"><span class="c-red"></span>结束时间</label>
            <div class="col-6">
            	<input type="input" class="px" id="endtime" name="endtime" value="{$period.endtime}" placeholder="2016-12-31 23:59:59" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" >
            </div>
            <div class="col-3"></div>
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input name="fomr-add" class="btn btn-success " type="submit" value="&nbsp;提交&nbsp;">
            </div>
        </div>
    </form>
</div>
<script>
// 适配3.2
var site_url = '{:U("Admin/Upyun/upload", array(), false)}';
//用户-编辑
function manage_edit(title, url, id, w, h, pc) {
	var height = 440 + (h-1)*31;
	if(pc == null) {
		height -= 31;
	}
    layer_show(title, url, w, height);
}

function checkForm() {
	var fromtime = $('#fromtime').val();
	var endtime = $('#endtime').val();
	
	if(fromtime == '' || endtime == '') {
		alert('开始时间和结束时间不能为空！');
		return false;
	}
	
	var repfromtime = fromtime.replace(new RegExp('-',"gm"), '/');
	var fromseconds = (new Date(repfromtime)).getTime();
	
	var rependtime = endtime.replace(new RegExp('-', "gm"), '/');
	var endseconds = (new Date(rependtime)).getTime();
	
	if(isNaN(fromseconds) == true || isNaN(endseconds) == true) {
		alert('时间格式不对, 请重新检查！');
		return false;
	}
	
	if(endseconds < fromseconds) {
		alert('结束时间不能小于开始时间！');
		return false;
	}
	
	return true;
}

$(document).ready(function(){
	<if condition="$food neq null">
	var sid = {$sid};
	$("option").each(function(){
		var opt_val = $(this).val(); 
		if(opt_val == sid) {
			$(this).attr("selected",'');
		}
	});
	<else />
	var firstSort = $('#state-sel').children().first();
	firstSort.attr("selected",'');
	var sid = firstSort.val();
	$('#sid').val(sid);
	</if>
});
</script>